<template>
	<view class="">
		<view style="padding-top: 50%;" v-if="list&&!list.length">
			<u-empty text="暂无相关数据"></u-empty>
		</view>
		<scroll-view scroll-y v-else>
			<view class="m-5 p-5 bg-white rounded shadow flex justify-between items-center" v-for="i in list"
				@click="onList(i)">
				<view class="">
					<view class="">
						{{i.refRecordName}}
					</view>
					<view class="text-black-666">
						{{i.personTypeName}}
					</view>
				</view>
				<view class="">
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import request from '@/utils/request.js'
	import {
		route,
		setTitle,
		toast
	} from '../../utils/utils'

	export default {
		data() {
			return {
				list: null,
			}
		},
		onLoad(query) {
			const {
				type
			} = query
			this.type = type
			if (this.type == 2) {
				setTitle('选择仓库')
			}
			this.getBasePersonRelations()
		},
		methods: {
			onList({
				refRecordId
			}) {
				route('/pages/order/goods', {
					refRecordId,
					type: this.type
				})
			},
			getBasePersonRelations() {
				const userId = this.$store.state.user.userId
				request('basePersonRelations', {
					method: 'post',
					data: {
						userId
					}
				}).then(res => {
					const {
						shops,
						warehouses
					} = res
					if (!shops.length) {
						toast('您不在任何门店中，无法查看')
						setTimeout(uni.navigateBack, 1000)
					} else if (shops.length === 1) {

					} else {
						if (this.type == 2) {
							// 库存盘点
							this.list = warehouses
						} else {
							this.list = shops
						}
					}
				})
			}
		}
	}
</script>

<style>
</style>
